class EventEmitter{
    constructor(){
        this.eventList={

        }
    }
    on(eventName,cb){
        if(!this.eventList[eventName]){
            this.eventList[eventName]=[]
        }
        this.eventList[eventName].push(cb)
    } 
    emit(eventName){
        if(this.eventList[eventName]){
            const handelers =this.eventList[eventName].slice()
            handelers.forEach((item)=>{
                item()
            })
        }
    }
    off(eventName,cb){
        const callbacks =this.eventList[eventName]
        const index =callbacks.indexOf(cb)
        if(index !== -1){
            callbacks.splice(index,1)
        }
    }
    once(eventName,cb){
        const wrap= ()=>{
            cb()
            this.off(eventName,wrap)
        }
        this.on(eventName,wrap)
    }
}
